﻿using System.Threading.Tasks;
using Acme.BookStore2.Localization;
using Microsoft.Extensions.Localization;
using Volo.Abp;
using Volo.Abp.Domain.Services;

namespace Acme.BookStore2
{
    public class VehicleInspectionRecordManager : DomainService
    {
        private readonly IVehicleInspectionRecordRepository _vehicleInspectionRecordRepository;
        private readonly IVehicleRepository _vehicleRepository;
        protected IStringLocalizer<BookStore2Resource> Localizer { get; }
        
        public VehicleInspectionRecordManager(
            IVehicleRepository vehicleRepository,
            IVehicleInspectionRecordRepository vehicleInspectionRecordRepository, 
            IStringLocalizer<BookStore2Resource> localizer) 
        {
            _vehicleInspectionRecordRepository = vehicleInspectionRecordRepository;
            Localizer = localizer;
            _vehicleRepository = vehicleRepository;
        }
        
        public async Task CreateAsync(VehicleInspectionRecord vehicleInspectionRecord)
        {
            Check.NotNull(vehicleInspectionRecord, nameof(VehicleInspectionRecord));
            await ValidateVeichleAsync(vehicleInspectionRecord);
            await _vehicleInspectionRecordRepository.InsertAsync(vehicleInspectionRecord);
        }
        
        public async Task UpdateAsync(VehicleInspectionRecord vehicleInspectionRecord)
        {
            Check.NotNull(vehicleInspectionRecord, nameof(VehicleInspectionRecord));
            await ValidateVeichleAsync(vehicleInspectionRecord);
            await _vehicleInspectionRecordRepository.UpdateAsync(vehicleInspectionRecord);
        }
        
        public async Task DeleteAsync(VehicleInspectionRecord vehicleInspectionRecord)
        {
            Check.NotNull(vehicleInspectionRecord, nameof(vehicleInspectionRecord));
            var vehicle = await _vehicleRepository.GetAsync(vehicleInspectionRecord.VehicleId);
            vehicle.CheckMaintenance();
            await _vehicleInspectionRecordRepository.DeleteAsync(vehicleInspectionRecord);
        }
        
        protected virtual async Task ValidateVeichleAsync(VehicleInspectionRecord vehicleInspectionRecord)
        {
        }
    }
}